package co.gov.medellin.ssti.sub.service;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Collection;
import java.util.List;

import javax.naming.NamingException;

import co.gov.medellin.ssti.sub.common.ConexionFactory;
import co.gov.medellin.ssti.sub.model.dao.DAOFactory;
import co.gov.medellin.ssti.sub.model.dao.ISecretariaDAO;
import co.gov.medellin.ssti.sub.model.dao.exception.DAOException;
import co.gov.medellin.ssti.sub.model.vo.AreaVO;

public class SecretariaService {

	/**
	 * Metodo que retorna la lista de todas las secretarias.
	 * 
	 * @return Collection de AreaVO.
	 * @throws DAOException
	 */
	public Collection<AreaVO> findSecretarias() throws DAOException {
		ISecretariaDAO secretariaDAO = null;

		try {
			Connection con = ConexionFactory.getInstance().getConnection();
			secretariaDAO = DAOFactory.getDAOFactory(DAOFactory.ORACLE)
					.getSecretariaDAO(con);
			return secretariaDAO.loadAllSecretarias();
		} catch (NamingException e) {
			throw new DAOException(e);
		} catch (SQLException e) {
			throw new DAOException(e);
		} finally {
			if (secretariaDAO != null) {
				if (!secretariaDAO.isConnClosed()) {
					secretariaDAO.close();
				}
			}
		}
	}

	/**
	 * 
	 * @param strCodeUsu
	 * @return
	 * @throws DAOException
	 */
	public List<AreaVO> findSecretariasByUser(String strCodeUsu)
			throws DAOException {
		ISecretariaDAO secretariaDAO = null;

		try {
			Connection con = ConexionFactory.getInstance().getConnection();
			secretariaDAO = DAOFactory.getDAOFactory(DAOFactory.ORACLE)
					.getSecretariaDAO(con);
			return secretariaDAO.loadSecretariasByUser(strCodeUsu);
		} catch (NamingException e) {
			throw new DAOException(e);
		} catch (SQLException e) {
			throw new DAOException(e);
		} finally {
			if (secretariaDAO != null) {
				if (!secretariaDAO.isConnClosed()) {
					secretariaDAO.close();
				}
			}
		}
	}
}
